﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WPFMediaKit.DirectShow.Controls;

namespace WpfPageDemo
{
    /// <summary>
    /// Page3.xaml 的交互逻辑
    /// </summary>
    public partial class Page3 : Page
    {
        public Page3()
        {
            InitializeComponent();
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            vce.VideoCaptureSource = MultimediaUtil.VideoInputNames[0];
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //RenderTargetBitmap bmp = new RenderTargetBitmap((int)vce.ActualWidth, (int)vce.ActualHeight,
            //    //vce是前台wpfmedia控件的name
            //    96, 96, PixelFormats.Default);
            ////为避免抓不全的情况，需要在Render之前调用Measure、Arrange
            ////为避免VideoCaptureElement显示不全，需要把
            ////VideoCaptureElement的Stretch="Fill"
            //vce.Measure(vce.RenderSize);
            //vce.Arrange(new Rect(vce.RenderSize));
            //bmp.Render(vce);
            //BitmapEncoder encoder = new JpegBitmapEncoder();
            //encoder.Frames.Add(BitmapFrame.Create(bmp));
            //using (MemoryStream ms = new MemoryStream())
            //{
            //    encoder.Save(ms);
            //    byte[] captureData = ms.ToArray();
            //    File.WriteAllBytes(@"./photo/" + Guid.NewGuid().ToString().Substring(0, 5) + ".jpg", captureData);
            //}
            //rect.SetValue(Image.WidthProperty, "123");
            //rect.SetValue(Image.HeightProperty, "123");
            //rect.SetValue(Image.VisibilityProperty, Visibility.Visible);
            //var mediaElementBase = new MediaUriElement();
            //mediaElementBase.VideoRenderer = new WPFMediaKit.DirectShow.MediaPlayers.VideoRendererType();
            //mediaElementBase.OpacityMask=new 

        }


    }
}
